package com.findbus.fragment;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public abstract class BaseFragment extends Fragment {
	public String stackTagrget;
	protected Context context;
	protected Bundle arguments;
	protected Activity activity;
	private FragmentCallBack<?, ?> callBack;

	protected BaseFragment() {
		// Required empty public constructor
		super();
	}

	protected BaseFragment(Context context, String stackTagrget) {
		// Required empty public constructor
		this();
		this.context = context;
		this.stackTagrget = stackTagrget;
	}

	@Override
	public void onAttach(Activity activity) {
		this.activity = activity;
		// TODO Auto-generated method stub
		super.onAttach(activity);
		if (context == null)
			this.context = activity;
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		arguments = getArguments();
		initData();
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		return initView(inflater);
	}

	public String getStackTagrget() {
		return stackTagrget;
	}

	public void setStackTagrget(String stackTagrget) {
		this.stackTagrget = stackTagrget;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
	}

	protected abstract void initData();

	protected abstract View initView(LayoutInflater inflater);

	public void setCallBack(FragmentCallBack<?, ?> callBack) {
		this.callBack = callBack;
	}

	public interface FragmentCallBack<E, T> {
		E callBack(E e, T t);
	}
}
